<template>
  <el-main>
    <el-table
      v-loading="loading"
      :data="tableData0_6"
      ref="tableData0_6"
      :span-method="objectSpanMethod"
      style="width: 100%"
      border
      class="table0_0"
    >      <el-table-column
             prop="itemTypeText"
             label="统计分类"
             width="200"
             header-align="center"
             align="center"
             fixed
           >
           </el-table-column>
           <el-table-column
             prop="itemDisplayText"
             label="分类"
             width="300"
             header-align="center"
             align="left"
             fixed
           >
           </el-table-column>
           <el-table-column
             prop="itemDisplayCode"
             label="代码"
             width="150"
             header-align="center"
             align="center"
             fixed
           >
           </el-table-column>
             <el-table-column
               label="合计"
               width="150"
               prop="dataSize_total"
               header-align="center"
               align="center"
             >
             </el-table-column>
          <el-table-column label="地形地貌数据" prop="dataSize_DXDM" width="120" header-align="center" align="center">
          </el-table-column>
          <el-table-column label="遥感影像数据" prop="dataSize_YGYX" width="120" header-align="center" align="center">
          </el-table-column>
          <el-table-column label="遥感影像解译样本数据" prop="dataSize_JYYB" width="120" header-align="center" align="center">
          </el-table-column>
          <el-table-column label="地表覆盖数据" prop="dataSize_DBFG" width="120" header-align="center" align="center">
          </el-table-column>
          <el-table-column label="地理国情要素数据" prop="dataSize_GQYS" width="120" header-align="center" align="center">
          </el-table-column>
          <el-table-column label="专题数据" prop="dataSize_ZTSJ" width="120" header-align="center" align="center">
          </el-table-column>
          <el-table-column label="地理国情统计分析数据" prop="dataSize_DLGQTJFX" width="120" header-align="center" align="center">
          </el-table-column>
        </el-table>
    <el-row>
      <el-col :span="2" :offset="2"><div>单位负责人：</div></el-col>
      <el-col :span="18"><div>{{formData.unit_leader}}</div></el-col>
    </el-row>
    <el-row>
      <el-col :span="2" :offset="2"><div>统计负责人：</div></el-col>
      <el-col :span="18"><div>{{formData.statistics_leader}}</div></el-col>
    </el-row>
    <el-row>
      <el-col :span="2" :offset="2"><div>填报人：</div></el-col>
      <el-col :span="18"><div>{{formData.informant}}</div></el-col>
    </el-row>
    <el-row>
      <el-col :span="2" :offset="2"><div>联系电话：</div></el-col>
      <el-col :span="18"><div>{{formData.iphone}}</div></el-col>
    </el-row>
    <el-row>
      <el-col :span="2" :offset="2"><div>报出日期：</div></el-col>
      <el-col :span="18"><div>{{formData.submit_date}}</div></el-col>
    </el-row>
  </el-main>
</template>

<script>
import { getDLGQReport } from "@/api/report/basic";


export default {
  name: "table0_6",
  data() {
    return {
    spanArr: [],
      spanArr1: [],
      pos:0,
      tableData0_6: [],
      //用于存储总计统计信息
      tableData0_6_total: [],
      //用于存储单位类型统计信息
      tableData0_6_unittype: [],
      //用于存储是否有偿统计信息
      tableData0_6_ispaid: [],
      loading: false,
      formData:{
        unit_leader: "",
        statistics_leader: "",
        informant: "",
        iphone: "",
        submit_date: ""
      }
    };
  },
  mounted: function () {
    // 组件创建完后获取数据，
    // 此时 data 已经被 observed 了
    //this.getSpanArr(this.tableData0_6);
    let date = new Date(); 
    this.formData.submit_date = date.getFullYear()+"-"+(date.getMonth()+1)+'-'+date.getDate();
    this.$emit("reportSearch","");
  },
  methods:{
      merageInit() {
        //初始化合并行的数组
        this.spanArr = [];
        this.pos = 0;
      },
      getSpanArr(data) {
      this.merageInit();
      for (var i = 0; i < data.length; i++) {
        if (i === 0) {
          this.spanArr.push(1);
          this.pos = 0;
        } else {
          // 判断当前元素与上一个元素是否相同
          if (data[i].itemTypeText === data[i - 1].itemTypeText) {
            this.spanArr[this.pos] += 1;
            this.spanArr.push(0);
          } else {
            this.spanArr.push(1);
            this.pos = i;
          }
        }
      }
    },
    objectSpanMethod({ rowIndex, columnIndex }) {
      if (columnIndex === 0) {
        const _row = this.spanArr[rowIndex];
        const _col = _row > 0 ? 1 : 0;
        return {
          rowspan: _row,
          colspan: _col
        }
      }
    },
    getReportData(queryParam) {
      this.loading = true;
      var condition = {};
      if(queryParam){
          console.log(queryParam);
          condition.beginTime = queryParam.beginTime;
          condition.endTime = queryParam.endTime;
          getDLGQReport(condition).then(response => {
                 this.tableData0_6 = response.rows;
                 this.total = response.total;
                 this.getSpanArr(this.tableData0_6);
                 this.loading = false;
          });
      }else{
        this.tableData0_5 = [];
        this.loading = false;
      }
    },
    export2Excel(name) {
        const tHeader1 = ["","", "","","","","","","",""];
        //const tHeader = name
        var filterVal = []
        for(var i in this.tableData0_6[0]){
          if(i != "itemType" && i != "itemCodes" && i != "itemTypeText"){
            filterVal.push(i)
          }
        }
        console.log(filterVal)
        require.ensure([], () => {
          const { export_json_to_excel } = require("@/views/basic-report/common/Export0_6");
          //const tHeader = theader;
          let tHeader = [name,'','','','','','','','','']
          const list = this.tableData0_6;
          //从上到下依次填充导出数据
          const data = [];
          
          
          data.push(['填报单位：','甘肃省基础地理信息中心','','','','','','','时期:',''])
          data.push(['分类','代码','合计','地形地貌数据','遥感影像数据','遥感影像解译样本数据','地表覆盖数据','地理国情要素数据','专题数据','地理国情统计分析数据']);
          data.push(tHeader1);
          data.push(['甲','乙','1','2','3','4','5','6','7','8'])

          this.tableData0_6_total = [];
          this.tableData0_6_total.push(this.tableData0_6[0]);
          const data_total = this.formatJson(filterVal, this.tableData0_6_total);

          data.push(data_total[0]);

          data.push(['一.按成果领用单位类型统计','-','-','-','-','-','-','-','-','-'])
          for(var i=1;i<this.tableData0_6.length-2;i++){
              const data_unittype = this.formatJson(filterVal, [this.tableData0_6[i]]);
              data.push(data_unittype[0]);
          }

          data.push(['二.按成果使用方式统计','-','-','-','-','-','-','-','-','-']);

          for(var i=this.tableData0_6.length-2;i<this.tableData0_6.length;i++){
              const data_ispaid = this.formatJson(filterVal, [this.tableData0_6[i]]);
              data.push(data_ispaid[0]);
          }
          
          data.push(['','','','','','','','','',''])
          data.push(['单位负责人：',this.formData.unit_leader,'','','','','','','',''])
          data.push(['统计负责人：',this.formData.statistics_leader,'','','','','','','',''])
          data.push(['填报人：',this.formData.informant,'','','','','','','',''])
          data.push(['联系电话：',this.formData.iphone,'','','','','','','',''])
          data.push(['报出日期：',this.formData.submit_date,'','','','','','','',''])
          export_json_to_excel(tHeader, data, name);
        });
    },
    formatJson(filterVal, jsonData) {
      return jsonData.map(v => filterVal.map(j =>{
        console.log(j);
        if((j.indexOf("dataSize_")==0)||(j.indexOf("coverageRange_")==0)){
          return Math.round(v[j]);
        }else{
          return v[j];
        }
        }));
    },
  }
};
</script>
<style scoped>
.el-row{
  margin:12px 0;
}
</style>
